<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
      th:replace="~{layout/base :: layout(~{::title}, ~{::section})}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录 - 知籁平台</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css">
    <style>
        .login-container {
            max-width: 450px;
            margin: 80px auto;
        }
        .card {
            border-radius: 10px;
            box-shadow: 0 10px 20px rgba(0,0,0,0.1);
        }
        .card-header {
            background-color: #f8f9fa;
            border-bottom: none;
            border-top-left-radius: 10px !important;
            border-top-right-radius: 10px !important;
            padding: 20px;
        }
        .card-body {
            padding: 30px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        .btn-login {
            background-color: #007bff;
            border-color: #007bff;
            padding: 10px 20px;
            font-weight: 500;
        }
        .btn-login:hover {
            background-color: #0069d9;
            border-color: #0062cc;
        }
        .alert {
            display: none;
        }
    </style>
</head>
<body>
    <!-- 页面内容部分 -->
    <section>
        <div class="container login-container">
            <div class="card">
                <div class="card-header text-center">
                    <h4 class="mb-0">用户登录</h4>
                </div>
                <div class="card-body">
                    <div class="alert alert-danger" id="loginError" role="alert" th:if="${param.error}" style="display: block;">
                        用户名或密码错误，请重试。
                    </div>
                    <div class="alert alert-success" id="registerSuccess" role="alert" th:if="${param.registered}" style="display: block;">
                        注册成功，请登录。
                    </div>
                    <div class="alert alert-success" id="logoutSuccess" role="alert" th:if="${param.logout}" style="display: block;">
                        您已成功退出登录。
                    </div>
                    
                    <form id="loginForm" th:action="@{/api/user/login}" method="post">
                        <!-- 确保CSRF令牌被添加 -->
                        <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}" />
                        
                        <div class="form-group">
                            <label for="username">用户名/邮箱</label>
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="fa fa-user"></i></span>
                                </div>
                                <input type="text" class="form-control" id="username" name="email" 
                                       placeholder="请输入用户名或邮箱" required>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="password">密码</label>
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text"><i class="fa fa-lock"></i></span>
                                </div>
                                <input type="password" class="form-control" id="password" name="password" 
                                       placeholder="请输入密码" required>
                            </div>
                        </div>
                        
                        <div class="form-group form-check">
                            <input type="checkbox" class="form-check-input" id="rememberMe" name="rememberMe">
                            <label class="form-check-label" for="rememberMe">记住我</label>
                        </div>
                        
                        <div class="form-group mb-2">
                            <button type="submit" class="btn btn-primary btn-login btn-block">
                                <i class="fa fa-sign-in mr-2"></i>登录
                            </button>
                        </div>
                        
                        <div class="text-center">
                            <p>还没有账号？ <a href="/register">立即注册</a></p>
                        </div>
                    </form>
                </div>
            </div>
        </div>

        <script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js"></script>
        <script>
        $(document).ready(function() {
            // 支持Ajax请求登录
            $("#loginForm").submit(function(e) {
                // 表单默认提交行为仍然有效
                // 此脚本仅添加额外处理，如需要前端验证等
            });
        });
        </script>
    </section>
</body>
</html> 